Ooops, little bug with the cross product.
[andmenj-acm.git] / 10081 - Tight words / 10081.cpp
bloba40bdec9472037cf5e861baef94b7cfbdc37de33
1 /*
2 Problem: 10081 - Tight words
3 Author: Andrés Mejía-Posada
4 (http://blogaritmo.factorcomun.org)
6 */
8 using namespace std;
9 #include <algorithm>
10 #include <iostream>
11 #include <iterator>
12 #include <sstream>
13 #include <fstream>
14 #include <cassert>
15 #include <climits>
16 #include <cstdlib>
17 #include <cstring>
18 #include <string>
19 #include <cstdio>
20 #include <vector>
21 #include <cmath>
22 #include <queue>
23 #include <deque>
24 #include <stack>
25 #include <map>
26 #include <set>
28 #define D(x) cout << #x " is " << x << endl
30 double dp[101][10];
32 int main(){
34 for (int k, n; scanf("%d %d", &k, &n)==2; ){
36 for (int last=0; last<=9; ++last) dp[1][last] = 1.0/(k+1);
38 for (int len=2; len<=n; ++len){
39 for (int last=0; last<=k; ++last){
40 dp[len][last] = dp[len-1][last];
41 if (last > 0) dp[len][last] += dp[len-1][last-1];
42 if (last < k) dp[len][last] += dp[len-1][last+1];
43 dp[len][last] /= k+1;
47 double ans = 0;
48 for (int last=0; last<=k; ++last) ans += dp[n][last];
49 printf("%.5lf\n", 100.0 * ans);
53 return 0;